let s:c_abbreviations = {
            \'a': 'assert',
            \'m': 'math',
            \'sb': 'stdbool',
            \'si': 'stdio',
            \'sin': 'stdint',
            \'sl': 'stdlib',
            \}

let s:cpp_abbreviations = {
            \'a': 'algorithm',
            \'d': 'deque',
            \'f': 'functional',
            \'i': 'iostream',
            \'m': 'map',
            \'n': 'numeric',
            \'q': 'queue',
            \'s': 'set',
            \'st': 'stack',
            \'um': 'unordered_map',
            \'us': 'unordered_set',
            \'v': 'vector',
            \}

for [key, value] in s:c_abbreviations->items()
    let s:cpp_abbreviations['c'.key] = 'c'.value
endfor

function import#c_cpp#add(name) abort
    let abbreviations = &filetype ==# 'c' ? s:c_abbreviations : s:cpp_abbreviations
    let name = abbreviations->get(a:name, a:name)
    if name[0] ==# '"'
        let name .= '"'
    else
        if &filetype ==# 'c' && name !~# '.h$'
            let name .= '.h'
        endif
        let name = '<'.name.'>'
    endif
    let position = getcurpos()[1:]
    let position[0] += 1
    let linenum = 1
    for line in getline(1, 5)
        if line =~# '^#include '
            break
        endif
        let linenum += 1
    endfor
    if linenum > 5
        let linenum = 1
    endif
    execute 'normal! '.linenum.'GO#include '.name."\<esc>Vip:sort\<cr>"
    call cursor(position)
endfunction
